/*
 * Implementation of checker "2.9     消除Cache伪共享"
 * Author: yu wang
 */
#include <fstream>
#include <iostream>
#include <list>
#include <queue>
#include <sstream>
#include <stack>
#include <string>

#include <clang/AST/AST.h>
#include <clang/AST/ASTConsumer.h>
#include <clang/AST/Expr.h>
#include <clang/AST/RecursiveASTVisitor.h>
#include <clang/AST/RecordLayout.h>
#include <clang/Frontend/ASTConsumers.h>
#include <clang/Frontend/ASTUnit.h>
#include <clang/Tooling/Tooling.h>
#include <llvm/Support/raw_ostream.h>

#include "framework/BasicChecker.h"
#include "framework/VariableAnalyzer.h"
#include "framework/Report.h"

using namespace clang;
using namespace llvm;
using namespace clang::driver;
using namespace clang::tooling;
using namespace std;


class FakeCachelineShare : public BasicChecker {
public:
    FakeCachelineShare(ASTResource *resource, ASTManager *manager,
                       CallGraph *call_graph, Config *configure)
            : BasicChecker(resource, manager, call_graph, configure) {};

    void check();

    float Threshold;
    int Min_Access;
    int DefaultLoopCount;

private:
    void analyzeStruct();

    void readConfig();

    int computeAccessFreq(const std::vector<int>& readArray, const std::vector<int>& writeArray);

    void analyzeRes(std::vector<std::pair<const RWAccess *, const VarDecl *>> &pairs);
};